package synchronization;

public class Producer extends Thread {
	
	private SharedQueue<Resource> queue;

	public Producer(SharedQueue<Resource> queue) {
		this.queue = queue;
	}

	@Override
	public void run() {
		while (! isInterrupted()) {
			Resource resource = new Resource();
			try {
				queue.enqueue(resource);
				System.out.printf("Producer %s: ", this.getName());
				System.out.printf("produced (added):   %1$tH:%1$tM:%1$tS.%1$tL. ", resource);
				queue.printState();
				int randomTime = (int)(500 + Math.random() * 1000);
				Thread.sleep(randomTime);
			} catch (InterruptedException ie) {
				return;
			}
		}
	}

}
